package com.design.AdapterMode.demo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Filter3 {

    private static final Map<Integer, String> filterMap = new HashMap<>(3);
    private static final List<String> sensitiveWords = new ArrayList<>(3);

    static {
        filterMap.put(1, "*");
        filterMap.put(2, "");
        filterMap.put(3, "-");

        sensitiveWords.add("你妈");
        sensitiveWords.add("干");
        sensitiveWords.add("菜");
        sensitiveWords.add("滚吧");
    }

    public String filter(Word word, Integer type){
        if(null == word){
            return null;
        }
        String str = filterMap.get(type);
        sensitiveWords.forEach(v->{
            if(word.getWord().contains(v)){
                System.out.println("敏感词 ：" + v + ", 替换");
                word.setWord(word.getWord().replaceAll(v, str));
            }
        });
        return word.getWord();
    }
}
